package com.example.demo;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Chapter212Application {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(Chapter212Application.class, args);
		//spring boot 2.0 提供的全新方法
		Binder binder = Binder.get(context.getEnvironment());

		// 绑定简单配置
		FooProperties foo = binder.bind("com.example", Bindable.of(FooProperties.class)).get();
		System.out.println(foo.getFoo());
		
		// 绑定List配置
		List<String> post = binder.bind("com.example.post", Bindable.listOf(String.class)).get();
		System.out.println(post);
		// 绑定List 對象配置
		List<PostInfo> posts = binder.bind("com.example.posts", Bindable.listOf(PostInfo.class)).get();
		System.out.println(posts);
	}
}
